<?

class Mdl_Blogroll extends MY_Model {

    function Mdl_Blogroll() {

        parent::MY_Model();

        $this->limit = 25;

    }

    function get($params = NULL) {

        $this->prep_params($params);

        if (isset($params['blogroll_id'])) {

            $this->db->where('blogroll_id', $params['blogroll_id']);

        }

        if (isset($params['paginate']) AND $params['paginate'] == TRUE) {

            $offset = ($this->page * $this->limit) - $this->limit;

            $this->db->limit($this->limit, $offset);

        }

        if (isset($this->is_admin)) {

            $this->db->where('inktype_blogroll.site_id', $this->session->userdata('site_id'));

        }

        else {

            $this->db->where('inktype_blogroll.site_id', $this->inktype->site_id);

        }

        $query = $this->db->get('inktype_blogroll');

        if (isset($params['paginate']) AND $params['paginate'] == TRUE) {

            $this->set_page_links();

        }

        if (isset($params['blogroll_id'])) {

            return $query->row();

        }

        else {

            return $query->result();

        }

    }

    function save() {

        $db_array = $this->prep_db_array();

        $db_array['site_id'] = $this->session->userdata('site_id');

        $db_array['url'] = prep_url($db_array['url']);

        if (!isset($this->uri_assoc['blogroll_id'])) {

            $this->db->insert('inktype_blogroll', $db_array);

        }

        else {

            $this->db->where('blogroll_id', $this->uri_assoc['blogroll_id']);

            $this->db->update('inktype_blogroll', $db_array);

        }

        $this->session->set_flashdata('success_save', TRUE);

    }

    function delete() {

        if (isset($this->uri_assoc['blogroll_id'])) {

            $this->db->where('blogroll_id', $this->uri_assoc['blogroll_id']);

            $this->db->delete('inktype_blogroll');

            $this->session->set_flashdata('success_delete', TRUE);

        }

    }

    function validate() {

        $this->fields = array(
            'title' =>  'Title',
            'url'   =>  'URL'
        );

        $this->rules = array(
            'title' =>  'required',
            'url'   =>  'required'
        );

        return $this->_validate();

    }

}

?>